<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>国家城市列表</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>
    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
</head>
<style>
</style>
<body>
    <div class="layui-fluid main">
        <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
                <div class="layui-form-item" style="float: left;">
                    <a href="{:url('admin/poi/addcountry')}" class="layui-btn layui-btn-sm a_menu">
                        添加国家
                    </a>
                </div>
        </fieldset>
        <table class="layui-table" lay-even="" lay-skin="line" >
            <colgroup>
                <col width="5%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
                <col width="10%">
            </colgroup>
            <thead>

            <tr >
                <th>ID</th>
                <th>排序权重</th>
                <th>分类</th>
                <th>国家</th>
                <th>城市</th>
                <th>北美玩乐<br>小程序城市</th>
                <th>服务号<br>商城热门<br>目的地</th>
                <th onclick="layer.tips('选中国家显示，选中的城市才会在WAP商城可见</br>TOB商城不受限制，选中城市即可显示。',this,{tips:[2,'#1E9FFF']})">
                    <i style="color: #1E9FFF" class="layui-icon layui-icon-tips" ></i>
                    商城/TOB显示
                </th>
                <th>抓取<br>viator商品</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            {volist name="city" id="vo"}
            {if $vo.groupid==0}
            <tr>
                <td>{$vo.id}</td>
                <td data-id="{$vo.id}" data-status="0" class="changeShow">展开 ▼</td>
                <td>{$vo.continent_name}({$vo.continent_eng_name})</td>
                <td><strong>{$vo.name}({$vo.eng_name})</strong></td>
                <td></td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="wxx_show" value="1" data-id="{$vo.id}" lay-filter="wxx_show" lay-skin="switch" <?php if($vo['wxx_recommend']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td></td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="show" value="1" data-id="{$vo.id}" lay-filter="show" lay-skin="switch" <?php if($vo['show']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td></td>
                <td class="operation-menu">
                    <a href="{:url('admin/city/addcountry',['id'=>$vo.id])}" class="layui-btn layui-btn-xs a_menu" style="margin:4px 10px 4px 0;font-size:12px;">修改</a>
                    <a href="{:url('admin/city/addcity',['groupid'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-warm a_menu"  style="margin:4px 10px 4px 0;font-size:12px;">添加</a>
                    {if $vo.deleted==1}
                    <a class="layui-btn layui-btn-xs layui-btn-normal use" data-id="{$vo.id}"  style="margin:4px 10px 4px 0;font-size:12px;">启用</a>
                    {else}
                    <a class="layui-btn layui-btn-xs layui-btn-danger delete" data-id="{$vo.id}"  style="margin:4px 10px 4px 0;font-size:12px;">弃用</a>
                    {/if}
                </td>
            </tr>
            {else}
            <tr data-pid="{$vo.groupid}" style="display: none;">
                <td>{$vo.id}</td>

                <td>{$vo.sort_weight}</td>
                <td></td>
                <td></td>
                <td><strong>{$vo.name}({$vo.eng_name})</strong></td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="wxx_show" value="1" data-id="{$vo.id}" lay-filter="wxx_show" lay-skin="switch" <?php if($vo['wxx_recommend']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="search" value="1" data-id="{$vo.id}" lay-filter="search" lay-skin="switch" <?php if($vo['popular']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="show" value="1" data-id="{$vo.id}" lay-filter="show" lay-skin="switch" <?php if($vo['show']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td>
                    <form class="layui-form" action="">
                        <div class="layui-form-item">
                            <div class="layui-input-block" style="margin-left: 0">
                                <input type="checkbox" name="getgoods" value="1" data-id="{$vo.id}" lay-filter="getgoods" lay-skin="switch" <?php if($vo['getgoods']==1){ echo 'checked';} ?> lay-text="on|off">
                            </div>
                        </div>
                    </form>
                </td>
                <td class="operation-menu">
                    <a href="{:url('admin/city/addcity',['id'=>$vo.id,'groupid'=>$vo.groupid])}" class="layui-btn layui-btn-xs a_menu" id="213" style="margin:4px 10px 4px 0;font-size:12px;">修改</a>
                    {if $vo.deleted==1}
                    <a class="layui-btn layui-btn-xs layui-btn-normal use" data-id="{$vo.id}"  style="margin:4px 10px 4px 0;font-size:12px;">启用</a>
                    {else}
                    <a class="layui-btn layui-btn-xs layui-btn-danger delete" data-id="{$vo.id}"  style="margin:4px 10px 4px 0;font-size:12px;">弃用</a>
                    {/if}
                </td>
            </tr>

            {/if}
            {/volist}

            </tbody>
        </table>


    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>

        <script>
            layui.use('form', function () {
                var form = layui.form;


                form.on('switch(city)', function(data){
                    var id= $(this).attr('data-id')
                    var    recommend;
                    if(data.elem.checked){
                        recommend =1;
                    }else{
                        recommend =0;
                    }
                    $.ajax({
                        url:"{:url('admin/City/recommend')}",
                        data:{'id':id,'recommend':recommend},
                        type:'post',
                        async: false,
                        success:function(res) {

                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)
                            }
                        }
                    })

                });

                form.on('switch(search)', function(data){
                    var id= $(this).attr('data-id')
                    var    popular;

                    if(data.elem.checked){
                        popular =1;
                    }else{
                        popular =0;
                    }
                    $.ajax({
                        url:"{:url('admin/City/recommend')}",
                        data:{'id':id,'popular':popular},
                        type:'post',
                        async: false,
                        success:function(res) {

                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)

                            }
                        }
                    })
                });

                form.on('switch(getgoods)', function(data){
                    var id= $(this).attr('data-id')
                    var popular;

                    if(data.elem.checked){
                        popular =1;
                    }else{
                        popular =0;
                    }
                    $.ajax({
                        url:"{:url('admin/City/getgoods')}",
                        data:{'id':id,'getgoods':popular},
                        type:'post',
                        async: false,
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)

                            }
                        }
                    })
                });

                form.on('switch(show)', function(data){
                    var id= $(this).attr('data-id')
                    var popular;

                    if(data.elem.checked){
                        popular =1;
                    }else{
                        popular =0;
                    }
                    $.ajax({
                        url:"{:url('admin/City/setshow')}",
                        data:{'id':id,'show':popular},
                        type:'post',
                        async: false,
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)
                            }
                        }
                    })
                });


                form.on('switch(wxx_show)', function(data){
                    var id= $(this).attr('data-id')
                    var show;
                    if(data.elem.checked){
                        show =1;
                    }else{
                        show =0;
                    }
                    $.ajax({
                        url:"{:url('admin/City/wxx_recommend')}",
                        data:{'id':id,'show':show},
                        type:'post',
                        async: false,
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.reload();
                                },1500)

                            }
                        }
                    })
                });
            });
        </script>
        <script type="text/javascript">

            $('.delete').click(function(){
                var id = $(this).attr('data-id');
                layer.confirm('确定要弃用吗?<br>弃用后会主动弃用城市和城市下的所有POI<br>请谨慎操作', function(index) {
                    $.ajax({
                        url:"{:url('admin/city/delcity')}",
                        type:"post",
                        data:{id:id,deleted:1},
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.href = res.url;
                                },1500)
                            }
                        }
                    })
                })
            })
            $('.use').click(function(){
                var id = $(this).attr('data-id');
                layer.confirm('确定要启用吗?<br>启用后会启用城市和城市下的所有POI', function(index) {
                    $.ajax({
                        url:"{:url('admin/city/delcity')}",
                        type:"post",
                        data:{id:id,deleted:0},
                        success:function(res) {
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.href = res.url;
                                },1500)
                            }
                        }
                    })
                })
            })
        </script>
        <script type="text/javascript">
            layui.use('layer', function(){
                var layer = layui.layer;
                $('.a_menu').click(function(){
                    var url = $(this).attr('href');
                    var a = 0;
                    $.ajax({
                        url:url
                        ,async:false
                        ,success:function(res){
                            if(res.code == 0) {
                                layer.msg(res.msg);
                                a = 1;
                            }
                        }
                    });
                    if(a === 0) {
                        layer.open({
                            type:2,
                            content:url,
                            area: ['65%', '90%'],
                            end:function(){
                                location.reload();
                            }
                        });
                    }
                    return false;
                });

                $(".changeShow").click(function(){
                    var id = $(this).attr('data-id');
                    var status = $(this).attr('data-status');
                    $(this).attr('data-status',parseInt(status)>0?0:1);
                    $(this).text(parseInt(status)>0?"展开 ▼":"收起 ▲");
                    $.each($('tr[data-pid='+id+']'),function(i,v){
                        (function (v) {
                            $(v).toggle(100);
                        })(v)
                    })
                })
            });
        </script>

</body>
</html>
